home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 105 (1991-02)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 105 (1991-02)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / AmigaUUCP / uucico / uux.c < prev    next >
C/C++ Source or Header  |  1991-02-10  |  4KB  |  210 lines

  1.  
  2. /*
  3.  *  UUX.C
  4.  *
  5.  *  Copyright 1988 by William Loftus.    All rights reserved.
  6.  *
  7.  *  Example: 1> uux mail-message "burdvax!rmail wpl"
  8.  *
  9.  *  NOTE:   UUX uses C.<host>N<seqno> instead of C.<host>A<seqno> to ensure
  10.  *        UUX transfers occur *after* any email
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "version.h"
  17. #include "protos.h"
  18.  
  19. IDENT(".06");
  20.  
  21. char *NodeName;
  22. char CutNodeName[8];
  23.  
  24. char user[128];
  25. char file_name[128];
  26. char command[128];
  27.  
  28. char ExecFile[128];
  29. char RemoteExecFile[128];
  30. char CommandFile[128];
  31. char DataFile[128];
  32. char RemoteDataFile[128];
  33. int seq;
  34.  
  35. char path[128];
  36.  
  37. void GetTo();
  38. void GetSubject();
  39.  
  40. #define TRUE 1
  41. #define FALSE 0
  42.  
  43. int
  44. brk()
  45. {
  46.     return(0);
  47. }
  48.  
  49. main(argc, argv)
  50. int argc;
  51. char **argv;
  52. {
  53.     int error;
  54.     char *up = GetUserName();
  55.  
  56.     NodeName = FindConfig(NODENAME);
  57.     strncpy(CutNodeName, NodeName, 7);
  58.  
  59.     onbreak(brk);
  60.     if (up == NULL) {
  61.     printf("couldn't find config entry for %s\n", USERNAME);
  62.     exit(1);
  63.     }
  64.     strcpy(user, up);
  65.  
  66.     getcwd(path,128);
  67.     chdir(GetConfigDir(UUSPOOL));
  68.     if (argc == 3) {
  69.     strcpy(file_name, argv[1]);
  70.     strcpy(command, argv[2]);
  71.     } else {
  72.     printf("Usage: uux file-name command\n");
  73.     printf("Example: 1> uux mail-message \"burdvax!rmail wpl\"\n");
  74.     chdir(path);
  75.     exit(1);
  76.     }
  77.     seq = GetSequence(4);
  78.     if (seq >= 0)
  79.     error = Queue();
  80.     UnLockFile(ExecFile);
  81.     UnLockFile(CommandFile);
  82.     UnLockFile(DataFile);
  83.     chdir(path);
  84.     if (seq < 0 || error < 0)
  85.     exit(1);
  86.     return(0);
  87. }
  88.  
  89. Queue()
  90. {
  91.     FILE *fp;
  92.     char system_name[32];
  93.     int bang;
  94.     int error;
  95.  
  96.     bang = (int)strchr(command,'!');
  97.     bang = bang - (int)command;
  98.  
  99.     strncpy(system_name, command, bang);
  100.  
  101.     system_name[bang] = '\0';
  102.  
  103.     if (!is_in_L_sys_file(system_name)) {
  104.     printf ("System \"%s\" not in L.sys file.\n", system_name);
  105.     return(-1);
  106.     }
  107.  
  108.     system_name[7] = '\0';
  109.  
  110.     /*
  111.      *    exec_file    Exec file as it appears on remote machine
  112.      *    x_exec_file    Remote's Exec file as it appears on this machine
  113.      *    command_file    Command file (this machine only)
  114.      *    data_file    DataFile as it appears on
  115.      *    x_data_file
  116.      *
  117.      *    local (overload)    txfer_to    remote (uunet)
  118.      *
  119.      *        C.uunetNxxxx    <not txfered>        command file
  120.      *        D.uunetXxxxx    X.overloaXxxxx        exec / Coexec
  121.      *        D.uunetBxxxx    D.overloaBxxxx        data file
  122.      */
  123.  
  124.     sprintf(CommandFile,"C.%sN%04d", system_name, seq);
  125.     sprintf(ExecFile,   "D.%sX%04d", system_name, seq);
  126.     sprintf(DataFile,   "D.%sB%04d", system_name, seq);
  127.     ++seq;
  128.     sprintf(RemoteExecFile, "X.%sX%04d", CutNodeName, seq);
  129.     ++seq;
  130.     sprintf(RemoteDataFile, "D.%sB%04d", CutNodeName, seq);
  131.  
  132.     LockFile(CommandFile);
  133.     LockFile(ExecFile);
  134.     LockFile(DataFile);
  135.  
  136.     fp = fopen(ExecFile,"w");
  137.     if (fp) {
  138.     fprintf(fp,"U %s %s\n", user, NodeName);
  139.     fprintf(fp,"F %s\n", RemoteDataFile);
  140.     fprintf(fp,"I %s\n", RemoteDataFile);
  141.     fprintf(fp,"C %s\n", (char *)command + bang + 1);
  142.     fclose(fp);
  143.     } else {
  144.     perror(ExecFile);
  145.     return(-1);
  146.     }
  147.  
  148.     fp = fopen(CommandFile, "w");
  149.     if (fp) {
  150.     fprintf(fp,"S %s %s %s - %s 0666\n",
  151.         DataFile,
  152.         RemoteDataFile,
  153.         user,
  154.         DataFile
  155.     );
  156.     fprintf(fp,"S %s %s %s - %s 0666\n",
  157.         ExecFile,
  158.         RemoteExecFile,
  159.         user,
  160.         ExecFile
  161.     );
  162.     fclose(fp);
  163.     } else {
  164.     perror(CommandFile);
  165.     return(-1);
  166.     }
  167.     chdir(path);
  168.     error = Copy(file_name, DataFile);
  169.     chdir(GetConfigDir(UUSPOOL));
  170.     return(error);
  171. }
  172.  
  173. /*
  174.  * Read the control file and grab a few parameters.
  175.  */
  176.  
  177. Copy(from, to)
  178. char *from;
  179. char *to;
  180. {
  181.     FILE *fd;
  182.     FILE *td;
  183.     int c;
  184.     static char to_buf[128];
  185.  
  186.     fd = fopen(from, "r");
  187.     if (!fd) {
  188.     printf("Could not open %s.\n", from);
  189.     perror(from);
  190.     return(-1);
  191.     }
  192.  
  193.     strcpy(to_buf, MakeConfigPath(UUSPOOL, to));
  194.  
  195.     td = fopen(to_buf, "w");
  196.     if (!td) {
  197.     printf("Could not open %s.\n", to_buf);
  198.     perror(to);
  199.     return(-1);
  200.     }
  201.     while ((c = fgetc(fd)) != EOF) {
  202.     fputc((char)c, td);
  203.     }
  204.     fclose(fd);
  205.     fclose(td);
  206.     return(1);
  207. }
  208.  
  209.  
  210.